package modelinitializer;

import com.jme3.asset.AssetManager;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import de.tsajar.es.render.SpatialInitializer;

/**
 *
 * @author Eike Foede
 */
public class CubeInitializer implements SpatialInitializer {

    AssetManager assetManager;

    public CubeInitializer(AssetManager asm) {
        this.assetManager = asm;
    }

    @Override
    public Spatial initialize(String spatial) {
        Material mat = new Material(assetManager,
                "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
        mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
        if (spatial.equals("arrow")) {
            Spatial s = assetManager.loadModel("Models/arrow1/arrow1.j3o");
            s.setMaterial(mat);
            return s;
        } else if (spatial.equals("scene")) {
            assetManager.registerLocator("town.zip", ZipLocator.class.getName());
            Spatial sceneModel = assetManager.loadModel("main.scene");
            sceneModel.setLocalScale(0.5f);
            AmbientLight al = new AmbientLight();
            al.setColor(ColorRGBA.White.mult(1.3f));
            sceneModel.addLight(al);
            DirectionalLight dl = new DirectionalLight();
            dl.setColor(ColorRGBA.White);
            dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
            sceneModel.addLight(dl);
            return sceneModel;
        } else {//default
            Box b = new Box(0.5f, 0.5f, 0.5f);
            Geometry g = new Geometry(spatial, b);
            g.setMaterial(mat);                   // set the cube's material

            return g;
        }
    }
}
